using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	public class ProcedureVersionControl : FreeFlowAdministrator.VersionControl
	{
    private System.Windows.Forms.Label libraryVersionsLabel;
    private FreeFlowAdministrator.ExtendedDataGrid libraryVersionsGrid;
		private System.ComponentModel.IContainer components = null;

		public ProcedureVersionControl()
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.components = new System.ComponentModel.Container();
      this.libraryVersionsLabel = new System.Windows.Forms.Label();
      this.libraryVersionsGrid = new FreeFlowAdministrator.ExtendedDataGrid();
      ((System.ComponentModel.ISupportInitialize)(this.libraryVersionsGrid)).BeginInit();
      this.SuspendLayout();
      // 
      // libraryVersionsLabel
      // 
      this.libraryVersionsLabel.Location = new System.Drawing.Point(8, 224);
      this.libraryVersionsLabel.Name = "libraryVersionsLabel";
      this.libraryVersionsLabel.Size = new System.Drawing.Size(100, 16);
      this.libraryVersionsLabel.TabIndex = 18;
      this.libraryVersionsLabel.Text = "Library versions:";
      // 
      // libraryVersionsGrid
      // 
      this.libraryVersionsGrid.AllowNavigation = false;
      this.libraryVersionsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                  | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.libraryVersionsGrid.CaptionVisible = false;
      this.libraryVersionsGrid.DataMember = "";
      this.libraryVersionsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
      this.libraryVersionsGrid.Location = new System.Drawing.Point(8, 248);
      this.libraryVersionsGrid.Name = "libraryVersionsGrid";
      this.libraryVersionsGrid.Size = new System.Drawing.Size(424, 136);
      this.libraryVersionsGrid.TabIndex = 17;
      // 
      // ProcedureVersionControl
      // 
      this.Controls.Add(this.libraryVersionsLabel);
      this.Controls.Add(this.libraryVersionsGrid);
      this.Name = "ProcedureVersionControl";
      this.Controls.SetChildIndex(this.libraryVersionsGrid, 0);
      this.Controls.SetChildIndex(this.libraryVersionsLabel, 0);
      ((System.ComponentModel.ISupportInitialize)(this.libraryVersionsGrid)).EndInit();
      this.ResumeLayout(false);
      this.PerformLayout();

    }
		#endregion

    public override void LoadVersion(FreeFlow.Administration.Version version)
    {
      base.LoadVersion(version);
      // library versions
      libraryVersionsLabel.Visible = (version.Server.SchemaVersion >= SchemaVersion.Version70);
      libraryVersionsGrid.Visible = (version.Server.SchemaVersion >= SchemaVersion.Version70);
      if (libraryVersionsGrid.Visible)
      {
        if (version is ProcedureVersion)
          libraryVersionsGrid.DataSource = ((ProcedureVersion)version).LibraryVersions;
        libraryVersionsGrid.ClearColumns();
        libraryVersionsGrid.AddColumn("Name");
        libraryVersionsGrid.AddColumn("PublishedTime", "Published");
        libraryVersionsGrid.AddColumn("VersionNumber", "Version");
        libraryVersionsGrid.AddColumn("Owner");
        libraryVersionsGrid.AddColumn("Description");
        libraryVersionsGrid.AddColumn("Type", "File type");
        libraryVersionsGrid.AddColumn("EworkVersion", "e-Work version");
        libraryVersionsGrid.AddColumn("Size", "Size (in bytes)");
        libraryVersionsGrid.AutosizeColumns();
      }
    }
	}
}

